<?php
// 验证数据库表
$host = '127.0.0.1';
$port = 3306;
$database = 'qiandao';
$username = 'root';
$password = 'root';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 验证打卡积分系统表 ===\n\n";
    
    // 获取所有checkin开头的表
    $stmt = $pdo->query("SHOW TABLES LIKE 'checkin_%'");
    $tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
    
    echo "创建的表数量: " . count($tables) . "\n\n";
    
    foreach ($tables as $table) {
        // 获取表的记录数
        $stmt = $pdo->query("SELECT COUNT(*) FROM {$table}");
        $count = $stmt->fetchColumn();
        
        echo "✓ {$table} (记录数: {$count})\n";
    }
    
    echo "\n=== 验证system_user表扩展 ===\n\n";
    
    // 检查system_user表的新字段
    $stmt = $pdo->query("SHOW COLUMNS FROM system_user LIKE 'store_id'");
    if ($stmt->rowCount() > 0) {
        echo "✓ system_user.store_id 字段已添加\n";
    }
    
    $stmt = $pdo->query("SHOW COLUMNS FROM system_user LIKE 'role_type'");
    if ($stmt->rowCount() > 0) {
        echo "✓ system_user.role_type 字段已添加\n";
    }
    
    echo "\n=== 查看初始化数据 ===\n\n";
    
    // 查看门店数据
    echo "门店数据:\n";
    $stmt = $pdo->query("SELECT id, name, code FROM checkin_store");
    $stores = $stmt->fetchAll(PDO::FETCH_ASSOC);
    foreach ($stores as $store) {
        echo "  ID:{$store['id']} {$store['name']} ({$store['code']})\n";
    }
    
    // 查看礼品数据
    echo "\n礼品数据:\n";
    $stmt = $pdo->query("SELECT id, name, points_required, stock FROM checkin_gift");
    $gifts = $stmt->fetchAll(PDO::FETCH_ASSOC);
    foreach ($gifts as $gift) {
        echo "  ID:{$gift['id']} {$gift['name']} - {$gift['points_required']}积分 (库存:{$gift['stock']})\n";
    }
    
    // 查看配置数据
    echo "\n系统配置:\n";
    $stmt = $pdo->query("SELECT `key`, value, description FROM checkin_setting");
    $settings = $stmt->fetchAll(PDO::FETCH_ASSOC);
    foreach ($settings as $setting) {
        echo "  {$setting['key']}: {$setting['value']} - {$setting['description']}\n";
    }
    
    echo "\n✅ 数据库表创建成功！\n";
    
} catch (PDOException $e) {
    echo "错误: " . $e->getMessage() . "\n";
}

